clear all
close all

%Figure: Raw hzd rates by demographic group
% data=xlsread('C:\Dropbox\Papers\DemogDecomp\FinalCodeAndTex\4Figures\Figure_2_data.xls');
data=xlsread('C:\Dropbox\Papers\DemogDecomp\REVISION\4FiguresUpdate\Figure2_update.xlsx');


nber=data(:,1);

jue=data(:,2:5);
jeu=data(:,6:9);
jei=data(:,10:13);
jui=data(:,14:17);
jie=data(:,18:21);
jiu=data(:,22:25);

X={jue,jeu,jei,jui,jie,jiu};
name={'UE','EU','EN','UN','NE','NU'};

figure,
for j=1:6
    subplot(3,2,j),
    set(0,'DefaultAxesColorOrder',[0 0 1;0 .6 0;1 0 0;0 0 0],...
        'DefaultAxesLineStyleOrder','-|-.|--|:')
    bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
    h1=gca;
    set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
    set(h1,'Fontsize',8)
    h2=axes('Position',get(h1,'Position'));
    set(h2,'Fontsize',8)
    plot(X{j}(:,1),'LineWidth',2);
    hold on, plot(X{j}(:,2),'LineWidth',2,'Color',[0 .6 0],'LineStyle','-.');
    hold on, plot(X{j}(:,3),'LineWidth',2,'Color',[1 0 0],'LineStyle','--');
    hold on, plot(X{j}(:,4),'LineWidth',1,'Color',[0 0 0],'LineStyle','-');
    set(h2,'YAxisLocation','left','Color','none')
    ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
    % ylim(h2,[4.9 6.3])
    text(-30,2,name{j}), ylim([-2 2])
    set(gca','Xticklabel',num2str((1980:10:2015)'))
    set(gca,'Xtick',17:4*10:length(nber)), xlim([1 length(nber)]),
    set(h2,'XLim',get(h1,'XLim'),'Layer','top')
    if j==6
        legend('Female <25','Female 25-54','Male <25','Male 25-54','Orientation','Horizontal','Fontsize',8)
    end
end





